//顶部导航
$(document).ready(function(){  
	//底部导航
	initPageFile();
	 setUser();
	 setChaptersList();
	 
});

var tiao = null;
var curChaptersID = "";//当前点击的章节
var curTheDraftID = ""; //草案编号
var curTheDraftTitle = "";//草案标题
//填充草案章节列表
function setChaptersList(){
	curTheDraftID = request.QueryString("id");//草案编号
	//获取数据库章节列表
	draftService.queryTitleById(curTheDraftID,function(data){
		curTheDraftTitle = data.TITLENAME;
		$("#main_title").html(curTheDraftTitle.substring(0,20));
		$("#TheDraftTitle").html(curTheDraftTitle);
	});
	//循环章节
	curChaptersID = "";
	var chapt = "";
	draftService.queryDirectory(curTheDraftID,function(data){
		for(var i=0;i<data.length;i++){
			if(i==0) curChaptersID = data[i].ID;
			chapt += '<li id=ch'+data[i].ID+' class=blue  onmouseover=setonmouseoverClass(\"'+data[i].ID+'\") onmouseout=setonmouseoutClass(\"'+data[i].ID+'\")><a href=javascript:clickItem(\"'+data[i].ID+'\")>'+data[i].ZJ+'&nbsp; &nbsp;'+data[i].ZJNAME+'</a></li>';
		}
		$("#ChaptersList").html(chapt);
		clickItem(curChaptersID);
	});
//	var chapt = "<li id='ch1' class='blue'  onmouseover='setonmouseoverClass(1)' onmouseout='setonmouseoutClass(1)'><a href='javascript:clickItem(1)'>第一章&nbsp; &nbsp;总则</a></li>"+
//                "<li id='ch2' class='white' onmouseover='setonmouseoverClass(2)' onmouseout='setonmouseoutClass(2)'><a href='javascript:clickItem(2)'>第二章&nbsp;&nbsp; 企业名称 </a></li>"+
//                "<li id='ch3' class='white' onmouseover='setonmouseoverClass(3)' onmouseout='setonmouseoutClass(3)'><a href='javascript:clickItem(3)'>第三章&nbsp;&nbsp; 企业名称的登记注册</a> </li>"+
//                "<li id='ch4' class='white' onmouseover='setonmouseoverClass(4)' onmouseout='setonmouseoutClass(4)'><a href='javascript:clickItem(4)'>第四章&nbsp;&nbsp; 企业名称的使用 </a></li>"+
//                "<li id='ch5' class='white' onmouseover='setonmouseoverClass(5)' onmouseout='setonmouseoutClass(5)'><a href='javascript:clickItem(5)'>第五章&nbsp;&nbsp; 监督管理与争议处理</a></li>"+
//                "<li id='ch6' class='white' onmouseover='setonmouseoverClass(6)' onmouseout='setonmouseoutClass(6)'><a href='javascript:clickItem(6)'>第六章&nbsp;&nbsp; 附则</a></li>";

}

function clickItem(id){
	//根据章节id获取小节列表
	document.getElementById("ch"+curChaptersID).className = "white";
	curChaptersID = id;
	document.getElementById("ch"+id).className = "blue";
	$("#CommentsTitle").text(document.getElementById("ch"+id).innerText);
	var html = "";
	draftService.queryItemByDirectory(id,function(data){
		tiao = data;
		for(var i=0;i<data.length;i++){
			html += "<div class='canzj_lieb2_RightText'>"+data[i].ZJSM+"</div>"+
			"<div class='canzj_lieb2_textarea'>"+
			"<textarea id='CommentsName"+data[i].ID+"' placeholder='意见内容5~200个字符'></textarea>"+
			"<div class='canzj_lieb2_button' style='width:740px;'>"+
			"<div class='canzj_lieb2_dx'>"+
			"<ul>"+
			"<li><input type='radio' name='field_name"+data[i].ID+"' checked='true' value='1'/></li>"+
			"<li>修改</li>"+
			"</ul>"+
			"<ul style='margin-right:10px; width:65px;'>"+
			"<li><input  type='radio' name='field_name"+data[i].ID+"' value='2'/></li>"+
			"<li>不同意</li>"+
			"</ul>"+
			"<ul style='width:65px;'>"+
			"<li><input type='radio' name='field_name"+data[i].ID+"' value='3'/></li>"+
			" <li>无意见</li>"+
			"</ul>"+
			"</div>"+
			"<div class='canzj_lieb2_ok'>"+
			"<ul>"+
			"<li><img src='images/canzj_lieb2_ok.png' title='提交' onClick=\"javascript:submitBut('"+data[i].ID+"')\"/></li>"+
			"<li><img src='images/canzj_lieb2_x.png' title='清空' onClick=\"javascript:resetBut('"+data[i].ID+"')\" /></li>"+
			"</ul>"+
			"</div>"+
			"</div>"+
			"</div>"+
			"<div style='background:#cecece; height:1px; width:760px; clear:both;'></div>"+
			"<div style='height:30px; width:760px;'></div>";
		}
		$("#while_item_list").html(html);
		$(".login_foot").css("position","static");
		if($(document).height()<=$(window).height()){
			$(".login_foot").css("position","absolute");
			$(".login_foot").css("top",$(window).height()-66);
		}
	});
}

function submitBut(id){
	var CommentsName = document.getElementById("CommentsName"+id).value;
	var field = document.getElementsByName("field_name"+id);
	var field_title = "";
	for(var i=0;i<field.length;i++){
		if(field[i].checked==true){
			field_title = field[i].value;
			break;
		}
	}
	if(CommentsName==""){
		Ext.example.msg('提示', "请输入意见内容。");
	}else{
		if(CommentsName.length<5 || CommentsName.length>200){
			Ext.example.msg('提示', "意见内容必须在5~200个字符。");
		}else{
			alert(CommentsName+"--"+field_title);
		}
		
	}
	
}
function submitBut0(){
	var CommentsName = document.getElementById("CommentsName").value;
	var field = document.getElementsByName("field_name");
	var field_title = "";
	for(var i=0;i<field.length;i++){
		if(field[i].checked==true){
			field_title = field[i].value;
			break;
		}
	}
	if(CommentsName==""){
		Ext.example.msg('提示', "请输入意见内容。");
	}else{
		if(CommentsName.length<5 || CommentsName.length>200){
			Ext.example.msg('提示', "意见内容必须在5~200个字符。");
		}else{
			alert(CommentsName+"--"+field_title);
		}
		
	}
	
}

function resetBut(id){
	document.getElementById("CommentsName"+id).value = "";
	var field_name = document.getElementsByName("field_name"+id);
	field_name[0].checked = true;
	
}
function resetBut0(){
	document.getElementById("CommentsName").value = "";
	var field_name = document.getElementsByName("field_name");
	field_name[0].checked = true;
	
}

//全文下载
function downLoadWord(){
	//curTheDraftID 获取草案的word文件下载
}

//整体意见
var updateUserWindow = null;
function OverallComments(){
	var html = "<div class='canzj_lieb2_RightText' style='height:40px;'>"+curTheDraftTitle+"</div>"+
	
    "<div class='canzj_lieb2_textarea'>"+
         "<textarea id='CommentsName' placeholder='意见内容5~200个字符'></textarea>"+
         "<div class='canzj_lieb2_button' style='width:740px;'>"+
            "<div class='canzj_lieb2_dx'>"+
                 "<ul>"+
                    "<li><input type='radio' name='field_name' checked='true' value='1'/></li>"+
                    "<li>修改</li>"+
                "</ul>"+
                 "<ul style='margin-right:10px; width:65px;'>"+
                    "<li><input  type='radio' name='field_name' value='2'/></li>"+
                    "<li>不同意</li>"+
                "</ul>"+
                 "<ul style='width:65px;'>"+
                    "<li><input type='radio' name='field_name' value='3'/></li>"+
                   " <li>无意见</li>"+
                "</ul>"+
            "</div>"+
            "<div class='canzj_lieb2_ok'>"+
                "<ul>"+
                    "<li><img src='images/canzj_lieb2_ok.png' title='提交' onClick='javascript:submitBut0()'/></li>"+
                    "<li><img src='images/canzj_lieb2_x.png' title='清空' onClick='javascript:resetBut0()' /></li>"+
                "</ul>"+
            "</div>"+
         "</div>"+
    "</div>";
	updateUserWindow = new Ext.Window({
		title : "草案整体意见",
		layout : 'fit',
		height : 250,
		width : 780,
		modal : true,
		closeAction :'hide',
		html:html,
		autoScroll:true,
		bodyStyle : 'background:#fff  repeat-y;'
	});
	updateUserWindow.show(Ext.get("zhengti"));
}

///////////////////////////////////////////////////////////////////////








function setonmouseoutClass(id){
	if(id==curChaptersID){
		document.getElementById("ch"+id).className = "blue";
	}else{
		document.getElementById("ch"+id).className = "white";
	}
}
function setonmouseoverClass(id){
	document.getElementById("ch"+id).className = "blue";
}


function setUser(){
	indexService.getUserBean(function(data){
		  UserBean = data;
		  if(UserBean.roleID!='5' && UserBean.roleID!='9'){//管理用户只能访问管理页面
			  window.location = "caoanAdminList.html";
		  }
		  if(UserBean.roleID!='5'){
			  $("#topuser").html("您好！"+UserBean.username+
				"<span style='width:10px; padding:0 10px;'>|</span><a href='LogoutServerServlet'>[退出]</a>");
		  }else{
			  $("#topuser").html("您还没有登录 <span style='width:10px; padding:0 10px;'>|</span><a href='"+UserBean.serverLogin+"'>[登录]</a>");
		  }
		  
	});
}

var request =
{
	QueryString : function(val)
	{
		var uri = window.location.search;
		var re = new RegExp("" +val+ "=([^&?]*)", "ig");
		return ((uri.match(re))?(uri.match(re)[0].substr(val.length+1)):null);
	}
};

function initPageFile(){
	//底部导航

	if($(document).height()<=$(window).height()){
        $(".login_foot").css("position","absolute");
        $(".login_foot").css("top",$(window).height()-66);
	  }
      $(window).resize(function(){   
           $(".login_foot").css("position","static");
		   if($(document).height()<=$(window).height()){
			$(".login_foot").css("position","absolute");
			$(".login_foot").css("top",$(window).height()-66);
	       }
      }); 
      
}
